/*
 * -------------------------------------------------------------------------- *
 * This is a Practice Work from the 'Algorithms, Part-I' course form Coursera.
 * 
 * -------------------------------------------------------------------------- *
 * Date:	28-Aug-2013 11:52:47 pm
 */
package com.gs.coursera.algorithms.week.one.uf;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public class QuickFind extends UnionFind{

	public QuickFind(int n) {
		super(n);
	}

	public void union(int p, int q){
		int pid = getNodes()[p];
		int qid = getNodes()[q];
		for (int i = 0; i < getNodes().length; i++) {
			if(getNodes()[i] == pid)
				getNodes()[i] = qid;
		}
	}
	
	public boolean isConnected(int p, int q){
		return getNodes()[p] == getNodes()[q];
	}
	
	
	
}
